import {createRouter,createWebHistory} from 'vue-router';
import axios from 'axios';

const routes = [
    {
        path: "",
        name: "goodslist",
        component: ()=>import("../views/goods.vue"),
    },
    {
        path: "/goods-detail/:id",
        name: "goodsd-etail",
        component: ()=>import("../views/goods-detail.vue"),
    },
    {
        path: "/checkorder",
        name: "checkorder",
        component: ()=>import("../views/checkorder.vue"),
    },
    {
        path: "/payment",
        name: "payment",
        component: ()=>import("../views/payment.vue"),
    },
];

const router = createRouter({
    history: createWebHistory(window.__MICRO_APP_BASE_ROUTE__ || process.env.BASE_URL),
    base: window.__MICRO_APP_BASE_URL__ || '/',
    routes
});


router.beforeEach((to, from, next) => {
    if (window.__MICRO_APP_ENVIRONMENT__) {
        // if(!localStorage.getItem("token")) {
        //     let data = window.microApp.getData();
        //     data.w7.login().then((code) => {
        //         axios.post('/api/thirdparty-cd/login', {
        //             code: code.code
        //         }).then(res => {
        //             localStorage.setItem("token", res.data.access_token);
        //             next()
        //         })
        //     })
        // }else {
        //     next()
        // }
        next();
    }else {
        next()
    }
})  

export default router;